Oh ok! Sheet no2 have a " " at the end ADAPTORS . So I correct this, but now it says that NewSheet already exists and yes there is a sheet by that name, at the newly created workgroup and the sript stops.
Posts by pantakos
-
-
At this line
wkb.Sheets(ws(i)).Activate
Gets an error 9 Subscript out of range
-
@rollis13 And another one. It keeps getting the name from sheet no2 2.POWER CABLES - ADAPTORS
Strange !
-
@rollis13 Unfortenetly I cant make it work
The code is this one now
Code
Display MoreSub BuildTemplateINm() Dim i As Long, j As Long, nr As Long Dim sht As Variant Dim cell As Variant, f As Range Dim Descript As String Dim shtName As Worksheet '<- added 'Set shtName = ActiveSheet '<- added Application.ScreenUpdating = False Application.DisplayAlerts = False Sheets.Add.Name = "NewSheet" Worksheets("NewSheet").Range("A1").Value = "Description" Worksheets("NewSheet").Range("B1").Value = "Quantity" 'nr = 2 sht = Array("D") ws = Array("1.Power Distribution - Dimmer", "2.POWER CABLES - ADAPTORS ", "3.CABLES (OTHER) - CABLE CROSS ") Sheets("NewSheet").Range("A2:B150").ClearContents 'Loop through all sheets in sheets array For i = LBound(ws) To UBound(ws) Set shtName = ActiveSheet '<- added nr = 2 ' Loop through all columns in the column array For c = LBound(sht) To UBound(sht) ' Find last row in column with data Sheets(ws(i)).Activate lr = Cells(Rows.Count, sht(c)).End(xlUp).Row ' Loop through all cells in column For Each cell In Range(Cells(1, sht(c)), Cells(lr, sht(c))) ' Check to see if value is numeric and not 0 If (IsNumeric(cell.Value)) And (cell.Value <> 0) Then ' Copy cells C, D, E to columns A, B, C of main sheet 'Range(Cells(cell.Row, "C"), Cells(cell.Row, "E")).Copy Sheets("NewSheet").Cells(nr, "A") Range(Cells(cell.Row, "C"), Cells(cell.Row, "E")).Copy Sheets("NewSheet").Cells(nr, "A").PasteSpecial Paste:=xlPasteValues Application.CutCopyMode = False ' Increment nr counter nr = nr + 1 ' 'Check to see if rows are full 'If nr > 70 Then 'MsgBox "Rows are full" 'Exit Sub 'End If End If Next cell Next c Next i Application.ScreenUpdating = False Const S = "NewSheet" Dim N$ N = ActiveWorkbook.Path & "\" & shtName.Name & ".xlsx" '<- changed Sheets(S).Move Application.DisplayAlerts = False ActiveWorkbook.SaveAs N, 51 Application.DisplayAlerts = True End Sub
-
Here is the example file again, this time without password for code
-
@rollis13 One more LAST help. (As you can understand I am newbie and trying to understand and learn). The code is working fine (extremely fine) but when I am trying to create a new Template, it all what it needs to do, but when I create the first template from sheet 1 (1.Power Distribution - Dimmer) working fine. When I am trying to create an other template (lets say from sheet 2.POWER CABLES - ADAPTORS) it appends the result to NewSheet (I dont know where finds it as it has been rename and moved) and creates the new Template with data from both sheets (append the results from both sheets, or all sheets that have data at column D).
I cant figure out why this happens, Maybe needs to make a "refresh" and delete all the other data from memory. I dont know. I am trying all night to figure out.
I attach the example for you. Thank you !
-
You are the man ! Thank you very much ! Really appreciate that !
-
@rollis13 is it possible to ask for something else for the same code?
I have change the current code to working only for column D , and copy values but also copy formatting. I am stuck! Can only copy values? not formatting.
Code
Display MoreSub BuildTemplateINm() Dim i As Long, j As Long, nr As Long Dim sht As Variant Dim cell As Variant, f As Range Dim Descript As String Dim shtName As Worksheet '<- added Set shtName = ActiveSheet '<- added Application.ScreenUpdating = False Application.DisplayAlerts = False Sheets.Add.Name = "NewSheet" Worksheets("NewSheet").Range("A1").Value = "Description" Worksheets("NewSheet").Range("B1").Value = "Quantity" nr = 2 sht = Array("D") ws = Array("1.Power Distribution - Dimmer", "2.POWER CABLES - ADAPTORS ", "3.CABLES (OTHER) - CABLE CROSS ") Sheets("NewSheet").Range("A2:B150").ClearContents 'Loop through all sheets in sheets array For i = LBound(ws) To UBound(ws) ' Loop through all columns in the column array For c = LBound(sht) To UBound(sht) ' Find last row in column with data Sheets(ws(i)).Activate lr = Cells(Rows.Count, sht(c)).End(xlUp).Row ' Loop through all cells in column For Each cell In Range(Cells(1, sht(c)), Cells(lr, sht(c))) ' Check to see if value is numeric and not 0 If (IsNumeric(cell.Value)) And (cell.Value <> 0) Then ' Copy cells C, D, E to columns A, B, C of main sheet Range(Cells(cell.Row, "C"), Cells(cell.Row, "E")).Copy Sheets("NewSheet").Cells(nr, "A") ' Increment nr counter nr = nr + 1 ' 'Check to see if rows are full 'If nr > 70 Then 'MsgBox "Rows are full" 'Exit Sub 'End If End If Next cell Next c Next i Application.ScreenUpdating = False Const S = "NewSheet" Dim N$ N = ActiveWorkbook.Path & "\" & shtName.Name & ".xlsx" '<- changed Sheets(S).Move Application.DisplayAlerts = False ActiveWorkbook.SaveAs N, 51 Application.DisplayAlerts = True End Sub
I think I have to change code line
I think I have to add
But I am confused...
Thank you !
-
Yes that will do the job! Thank you @rollis13 !!!
-
rolls13. Thank you for your answer.
I havent test the solution but I need name to be the active worksheet, the one I am retrieving the data from. It may be 1.Power Distribution - Dimmer or 2.PowerCycle2 or 3.Dimmers . the newly created sheet take the name of the sheet from the data is retrieved.
-
Hello ,
The code below is working fine and creates a new sheet.
The newly created sheet is saved by a constant name.
Can be saved with the name of the sheet whEre the new sheet created plus a number (or no number just the name).
(i,e. the name of the sheet that will get data and create a new sheet named 1.Power Distribution - Dimmer, so the new workgroup saved as this name)
I have uploaded example. The module need to be changed is Module5
Thanks
-
Code
Display MoreSub BuildInvoiceAll() Dim ws As Variant, arr1 As String, arr2 As String, arr3 As String, arr4 As String, arry As Variant Dim i As Long, j As Long, nr As Long Dim cell As Range, f As Range Dim Descript As String Dim all_numeric As Boolean all_numeric = True Application.ScreenUpdating = False 'Set array of worksheet names to copy from ws = Array("AUDIO", "LIGHTS") 'cells to AUDIO sheet arr1 = "E:E, J:J" 'cells to LIGHTS sheet arr2 = "E:E, J:J" 'cells to HOISTS sheet 'arr3 = "E:E, K:K" 'cells to DISTRO sheet 'arr4 = "E:E, K:K" arry = Array(arr1, arr2) nr = 14 Sheets("PROFORMA DRYHIRE").Range("A15:C70").ClearContents For i = LBound(ws) To UBound(ws) 'Loop through all shees in the array For Each cell In Sheets(ws(i)).Range(arry(i)) 'Loop through all cells in the multirange If Not IsNumeric(cell) Then all_numeric = False Exit For End If Next cell For Each cell In Sheets(ws(i)).Range(arry(i)) If cell > 0 Then 'See if anything entered in pieces Descript = cell.Offset(0, -3) 'get description from column B With Sheets("PROFORMA DRYHIRE") Set f = .Range("A15:A70").Find(Descript, , xlValues, xlWhole) If Not f Is Nothing Then nr = f.Row Else nr = nr + 1 If nr > 70 Then MsgBox "Rows are full" Exit Sub End If End If .Cells(nr, "A") = Descript 'Populate values in PROFORMA sheet .Cells(nr, "B") = cell 'get pieces from column E .Cells(nr, "C") = cell.Offset(0, -1) 'get price p/d from column D End With End If Next cell Next i Application.ScreenUpdating = False End Sub
Hello RoyUK. Thank you for your answer and effort. What I am trying to do is not to enter all the ranges i.e. E2:E45, K3:K88 etc but instead this to just enter K:K, E:E to check all the column. And furthermore, into E column there is text, and because I only need numeric values to do mathematical equation, I need to choose only numeric. I hope you understand. Thank you
-
Hello all,
I have the following code that works great. Because it will be big enough I want to choose only the numbers from E or J etc and not have to make choise (ie E34:E66. J15:J33)
VBA Code:
CodeSub BuildInvoiceAll() Dim ws As Variant, arr1 As String, arr2 As String, arr3 As String, arr4 As String, arry As Variant Dim i As Long, j As Long, nr As Long Dim cell As Range, f As Range Dim Descript As String Application.ScreenUpdating = False 'Set array of worksheet names to copy from ws = Array("AUDIO", "LIGHTS", "HOISTS - TRUSS - DRAPES", "DISTRO - CABLES - MISC") 'cells to AUDIO sheet arr1 = "E:E, J:J" 'cells to LIGHTS sheet arr2 = "E13:E34, J13:J59, E36:E59, E73:E89, J73:J82, J84:J91, E91:E98, J93:J101, E100:E109, J103:J113" 'cells to HOISTS sheet arr3 = "E13:E28, K13:K37, E30:E40, E42:E52, E67:E91, K67:K85, E106:E123, K106:K119, K121:K129, E127:E137" 'cells to DISTRO sheet arr4 = "E13:E35, K13:K50, E37:E50, E64:E116, K64:K88, K92:K108, K111:K120, E131:E148, K131:K148, K150:K159," & _ "E152:E180 , K163:K188 , K190:K203 , E184:E216 , K207:K238 , K240:K249 " arry = Array(arr1, arr2, arr3, arr4) nr = 14 Sheets("PROFORMA DRYHIRE").Range("A15:C70").ClearContents For i = LBound(ws) To UBound(ws) 'Loop through all shees in the array For Each cell In Sheets(ws(i)).Range(arry(i)) 'Loop through all cells in the multirange If cell > 0 Then 'See if anything entered in pieces Descript = cell.Offset(0, -3) 'get description from column B With Sheets("PROFORMA DRYHIRE") Set f = .Range("A15:A70").Find(Descript, , xlValues, xlWhole) If Not f Is Nothing Then nr = f.Row Else nr = nr + 1 If nr > 70 Then MsgBox "Rows are full" Exit Sub End If End If .Cells(nr, "A") = Descript 'Populate values in PROFORMA sheet .Cells(nr, "B") = cell 'get pieces from column E .Cells(nr, "C") = cell.Offset(0, -1) 'get price p/d from column D End With End If Next cell Next i Application.ScreenUpdating = False End Sub
Can this be done?
Thank you!
Note! This is also posted on mrexcel Forum https://www.mrexcel.com/board/…meric-with-range.1196052/
Also posted at https://stackoverflow.com/ques…5605/isnumeric-with-range
-
Hello all,
I have the following code that works great. Because it will be big enough I want to choose only the numbers from E or J etc and not have to make choise (ie E34:E66. J15:J33)
VBA Code:
CodeSub BuildInvoiceAll() Dim ws As Variant, arr1 As String, arr2 As String, arr3 As String, arr4 As String, arry As Variant Dim i As Long, j As Long, nr As Long Dim cell As Range, f As Range Dim Descript As String Application.ScreenUpdating = False 'Set array of worksheet names to copy from ws = Array("AUDIO", "LIGHTS", "HOISTS - TRUSS - DRAPES", "DISTRO - CABLES - MISC") 'cells to AUDIO sheet arr1 = "E:E, J:J" 'cells to LIGHTS sheet arr2 = "E13:E34, J13:J59, E36:E59, E73:E89, J73:J82, J84:J91, E91:E98, J93:J101, E100:E109, J103:J113" 'cells to HOISTS sheet arr3 = "E13:E28, K13:K37, E30:E40, E42:E52, E67:E91, K67:K85, E106:E123, K106:K119, K121:K129, E127:E137" 'cells to DISTRO sheet arr4 = "E13:E35, K13:K50, E37:E50, E64:E116, K64:K88, K92:K108, K111:K120, E131:E148, K131:K148, K150:K159," & _ "E152:E180 , K163:K188 , K190:K203 , E184:E216 , K207:K238 , K240:K249 " arry = Array(arr1, arr2, arr3, arr4) nr = 14 Sheets("PROFORMA DRYHIRE").Range("A15:C70").ClearContents For i = LBound(ws) To UBound(ws) 'Loop through all shees in the array For Each cell In Sheets(ws(i)).Range(arry(i)) 'Loop through all cells in the multirange If cell > 0 Then 'See if anything entered in pieces Descript = cell.Offset(0, -3) 'get description from column B With Sheets("PROFORMA DRYHIRE") Set f = .Range("A15:A70").Find(Descript, , xlValues, xlWhole) If Not f Is Nothing Then nr = f.Row Else nr = nr + 1 If nr > 70 Then MsgBox "Rows are full" Exit Sub End If End If .Cells(nr, "A") = Descript 'Populate values in PROFORMA sheet .Cells(nr, "B") = cell 'get pieces from column E .Cells(nr, "C") = cell.Offset(0, -1) 'get price p/d from column D End With End If Next cell Next i Application.ScreenUpdating = False End Sub
Can this be done?
Thank you!
Note! This is also posted on mrexcel Forum https://www.mrexcel.com/board/…meric-with-range.1196052/
-
Also, is it possible to check if the entry exists?
Thank you,
Makis
-
Hello all,
I want to create an alert when I create an event based on a google spreadsheet.
The code is
Code
Display More// Δημιουργία Μενού function onOpen(){ const ss = SpreadsheetApp.getActive(); const menuEntries = []; menuEntries.push({name: 'Εισαγωγή σε Ημερολόγιο', functionName: 'scheduleShifts'}); ss.addMenu('Carousel', menuEntries); } // Δημιουργία Event function scheduleShifts() { var spreadsheet = SpreadsheetApp.getActiveSheet(); var calendarID = spreadsheet.getRange("B2").getValue(); var eventCal = CalendarApp.getCalendarById(calendarID); const signups = spreadsheet.getRange("A4:D110") .getValues() .filter(row => row.every(String)); for (x=0; x<signups.length;x++) { var shift = signups[x]; var startTime = shift[0]; var action= shift[2]; var description= shift[1]; var endTime= shift[3]; eventCal.createEvent(action, startTime, endTime, { description: shift[1] } ).setColor(4) } }
And the sample is here
Thank you in advance,
Makis
-
royUK Yes! Finally with a lot of search and your valuable help I finally did it!
I can bring monthly sum for every aspect.
Now just I have to figure out about the users and the color (change color when one day is finished)
Users I am good, the only problem is the color. Can you help me again?
Change Color: At calendar lets say that the day is 29-6-2021 and is highlighted yellow because is the today(). Is it possible when day ends to change color to Red? If it is not, then I am ok, I am good!
CalendarCAFEv5_semifinal2.xlsm
Thank you!
-
-
Yes! I can do that!!! I will upload the translated file. Thank you!
-
You see , as you have understand I am not a heavy excell user. I am an IT but at the other side, hardware, switches, networks, cabling etc. So, I cant built a database, like sql I suppose, thats why I stick to excel, in order to help the company I am working for, to do the job. I am really greatfull that you answered my posts. Thank you. I will stick with what I gave so far. I will calculate months by hand. Thank you again!!!