Hi guys,
I'm trying to find a way to copy a range from and until a cell contains the specific text "Total". L1/2 are the header, so the data should begin copying at L3:Q for the blue background. However, I want to stop copying once it reaches "Total". I'm currently just being thrown errors and have not been able to figure out how to accomplish this on my own, fairly new to VBA.
In my Sub Main() I have a While loop that goes through every sheet, activates it and calls addSetB (add blue background data). However, my "addSetB" call throws the error on the rowNum line. "Compile error: Named argument not found." Highlighting "Col:="L" as the error.
While (sht < maxSht)
Sheets(sht).Activate
Call addSetB
' Increment and grab next sheet
sht = sht + 1
Wend
' Dynamically coded as it varies sheet to sheet
' This example it should be grabbing L3:Q16
Sub addSetB()
Dim rowNum As Long
rowNum = Cells.Find(Col:="L", str:="Total", Direction:=xlNext)
' Copy blue background range
Range("L3:Q" & rowNum).Copy
' Activate CIMS sheet and paste in last available blank cell
Sheets("DATA").Activate
Cells(Range("A" & rows.Count).End(xlUp).Row + 1, 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub
I'm trying to find a way to copy a range from and until a cell contains the specific text "Total". L1/2 are the header, so the data should begin copying at L3:Q for the blue background. However, I want to stop copying once it reaches "Total". I'm currently just being thrown errors and have not been able to figure out how to accomplish this on my own, fairly new to VBA.
In my Sub Main() I have a While loop that goes through every sheet, activates it and calls addSetB (add blue background data). However, my "addSetB" call throws the error on the rowNum line. "Compile error: Named argument not found." Highlighting "Col:="L" as the error.
While (sht < maxSht)
Sheets(sht).Activate
Call addSetB
' Increment and grab next sheet
sht = sht + 1
Wend
' Dynamically coded as it varies sheet to sheet
' This example it should be grabbing L3:Q16
Sub addSetB()
Dim rowNum As Long
rowNum = Cells.Find(Col:="L", str:="Total", Direction:=xlNext)
' Copy blue background range
Range("L3:Q" & rowNum).Copy
' Activate CIMS sheet and paste in last available blank cell
Sheets("DATA").Activate
Cells(Range("A" & rows.Count).End(xlUp).Row + 1, 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End Sub