create an input box to select from and to cell in excel vb

bhatipuru

New Member
Joined
Jun 25, 2012
Messages
20
Hello all,

I have a report number of the columns are the same but number of row's changes.

I would like an input box to ask me to enter the beganing cell and ending cell for me to select and use my macro for formatting.

ex:A13 to S27- Where "A13" to "S13" is the starging point and ending point could be A20 to S20 or A14 to S14
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Dim x as Range
Set x = Application.InputBox("Select range", Type:-8)
 
Upvote 0
Perfect. Thanks. It works.

I guess selection did not work. I want to update or change some formatting on the slection.

EX: After selecting "A13:S27", I want to change the borders or formatting for the selected cells only. NOTE: "The selection may different on daily basis"

Set X = Application.InputBox("Select range", Type:=8)
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 1
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 1
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 1
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 1
.TintAndShade = 0
.Weight = xlMedium
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 1
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 1
.TintAndShade = 0
.Weight = xlThin
End With
 
Upvote 0
Change every instance of Selection to X

That's kind of the whole purpose of setting the Variable X to a specific range.
So that you can then refer to X in future code.
 
Upvote 0
Here is something else that is helpful. If you are implementing all borders just use one instance of With like below:

Code:
With Selection.Borders
.LineStyle = xlContinuous
.ColorIndex = 1
.TintAndShade = 0
.Weight = xlMedium
End With

Noe after the line:

With Selection.Borders , there is no specific line mentioned. This allows you to implement borders around and inside the range.
 
Upvote 0

Forum statistics

Threads
1,207,402
Messages
6,078,270
Members
446,324
Latest member
JKamlet

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