InputBox to insert the last column filled.

JODomingos

New Member
Joined
Jul 11, 2020
Messages
48
Office Version
  1. 2016
Platform
  1. Windows
Hi Guys.

I have a macro which is based on replace multiple cells in a specific range. This range is variable, because i need to input the last column filled with data. So whenever i need to run, i need to get in visual basic codes and change the code line. Ih there a way to create an input box that i could insert the last column instead of get inside the visual basic modules to change it?

Follows below the code: The bold "EGQ" word is the variable column which i must to filled before run it.

Sub ReplaceWithAverage()
Dim Cell As Range
For Each Cell In Range("C4", Cells(Rows.Count, "EGQ").End(xlUp)).SpecialCells(xlConstants)
Cell.Replace "NN", Cell.End(xlDown).Value, xlWhole, , , , False, False
Next
End Sub


Thanks in advance
 

Some videos you may like

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,414
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Try this. Note that the quote marks around EGQ have been removed.

Rich (BB code):
Sub ReplaceWithAverage()
Dim Cell As Range, EGQ As String
EGQ = InputBox("Enter the column letter(s) for the last filled column")
If EGQ = "" Then Exit Sub  'user clicked Cancel
For Each Cell In Range("C4", Cells(Rows.Count, EGQ).End(xlUp)).SpecialCells(xlConstants)
    Cell.Replace "NN", Cell.End(xlDown).Value, xlWhole, , , , False, False
Next
End Sub
 
Solution

JODomingos

New Member
Joined
Jul 11, 2020
Messages
48
Office Version
  1. 2016
Platform
  1. Windows
Try this. Note that the quote marks around EGQ have been removed.

Rich (BB code):
Sub ReplaceWithAverage()
Dim Cell As Range, EGQ As String
EGQ = InputBox("Enter the column letter(s) for the last filled column")
If EGQ = "" Then Exit Sub  'user clicked Cancel
For Each Cell In Range("C4", Cells(Rows.Count, EGQ).End(xlUp)).SpecialCells(xlConstants)
    Cell.Replace "NN", Cell.End(xlDown).Value, xlWhole, , , , False, False
Next
End Sub
It worked Joemo. Thank you so much. I really a appreciate your support.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,875
Messages
5,627,410
Members
416,245
Latest member
Xterminat

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
Top