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
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
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
 
Upvote 0
Solution
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.
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,852
Members
449,096
Latest member
Erald

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