How to auto-fill until the last row of data based on user-specified input on a separate worksheet

Alex89

New Member
Joined
May 30, 2019
Messages
34
Hi everyone,

I'm trying to autofill column A in "Master Publisher Content" based on a user-specified value in "Enter Info" in cell H3. The catch is that I only want to fill column A based on the last row of data in "Master Publisher Content." I'm using column C to find the last row of data, but it doesn't seem to be working the way I would like. Any suggestions would be really appreciated!! Thank you so much in advance


Sub CopyMarketName()
'
' CopyMarketName Macro
Dim wksData As Worksheet
Dim lngLastRow As Long


Set wksData = ThisWorkbook.Worksheets("Master Publisher Content")




With wksData
lngLastRow = .Range("C" & .Rows.Count).End(xlUp).Row
Set rngData = .Range("C2:C" & lngLastRow)
End With




ThisWorkbook.Worksheets("Enter Info").Range("H2").Select.Copy
Sheets("Master Publisher Content").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
Selection.AutoFill Destination:=Range(lngLastRow), Type:=xlFillDefault
Range(lngLastRow).Select
Sheets("Enter Info").Select




End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You don't really need to use auto fill for that.

Code:
Sub CopyMarketName() '
' CopyMarketName Macro
Dim wksData As Worksheet
Dim lngLastRow As Long
Set wksData = ThisWorkbook.Worksheets("Master Publisher Content")
    With wksData
        lngLastRow = .Range("C" & .Rows.Count).End(xlUp).Row
        Set RngData = .Range("C2:C" & lngLastRow)
    End With
ThisWorkbook.Worksheets("Enter Info").Range("H2").Copy
wksData.Range("A2:A" & lngLastRow).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
End Sub

BTW, when posting code, it is easier to read and work with if you use code tags to hold its format. To apply the code tags, simply select the text of the code, then click the pound symbol (#) in the tool bar of the thread reply window.
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top