Hello Forum,
I have an excel document with a few dozen sheets. In each sheet column B is empty and I need to fill that column (starting from the third row –B3) all the way down to the last used row of the sheet with a specific text (a product name).
Each sheet has a different text that needs to be filled in.
I am new to VBA but with a lot of research and ´forum-hunting´ I pieced together a macro.
The Macro references column A to establish in which row it should stop inputting text in column B.
My problem is the following:
The macro works great on the first sheet. (sh1 ¨AD MOSTAZA Y MIEL¨).
BUT in all the rest of the sheets it keeps inputting the text far past the last row used!
Can anyone help me fix it please?
P.S.: I only posted the Macro with 5 sheets as an example. The Macro I need to use is pretty much the same just for more sheets.
![]()
Sub InputProductName() Dim sh1 As Worksheet Dim sh2 As Worksheet Dim sh3 As Worksheet Dim sh4 As Worksheet Dim sh5 As Worksheet Set sh1 = ActiveWorkbook.Sheets("AD MOSTAZA Y MIEL") Set sh2 = ActiveWorkbook.Sheets("AD SOYA Y LIMON") Set sh3 = ActiveWorkbook.Sheets("AD ACHIOTE") Set sh4 = ActiveWorkbook.Sheets("AD CESAR") Set sh5 = ActiveWorkbook.Sheets("AD CASA") LastRow = Range("A1:A" & Range("A1").End(xlDown).Row).Rows.Count sh1.Range("B3").Value = "AD MOSTAZA Y MIEL" sh1.Range("B3" & ":B" & LastRow).FillDown sh2.Range("B3").Value = "AD SOYA Y LIMON" Sh2.Range("B3" & ":B" & LastRow).FillDown sh3.Range("B3").Value = "AD ACHIOTE" sh3.Range("B3" & ":B" & LastRow).FillDown sh4.Range("B3").Value = "AD CESAR" sh4.Range("B3" & ":B" & LastRow).FillDown sh5.Range("B3").Value = "AD CASA" sh5.Range("B3" & ":B" & LastRow).FillDown End Sub
Bookmarks