ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Allowing for variable cell reference in macro (https://www.excelbanter.com/excel-worksheet-functions/61794-allowing-variable-cell-reference-macro.html)

tx12345

Allowing for variable cell reference in macro
 

Hi

What I'd like to figure out is how to get a macro to read from data
placed in a cell, and then apply that data to the macro.

like:

Sub Macro1()

Range("TBD<<").Select
Selection.sort Key1:=Range("I1"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False

End Sub


where the range is read from some other cell on the spreadsheet. so the
macro reads what is in the cell telling it what range to sort, and then
enters that in the Range("").Select area of the macro.

Otherwise I have to create a separate macro for every area that might
possibly apply. I'd like to create an intelligent macro that I tell
what range to sort, or delete, or copy, or paste, etc, whatever I want
to happen with the range of cells I select.

Any ideas?

Thx


--
tx12345
------------------------------------------------------------------------
tx12345's Profile: http://www.excelforum.com/member.php...o&userid=24776
View this thread: http://www.excelforum.com/showthread...hreadid=495872


Gary''s Student

Allowing for variable cell reference in macro
 
Let's say that A1 contains the text Z100, the following:


Sub Macro1()
Dim s As String
s = Cells(1, 1)
Range(s).Select
End Sub

will get the contents of A1 (as a string) convert it into a range and select
that range. You could apply it to ranges of more than one cell.
--
Gary's Student


"tx12345" wrote:


Hi

What I'd like to figure out is how to get a macro to read from data
placed in a cell, and then apply that data to the macro.

like:

Sub Macro1()

Range("TBD<<").Select
Selection.sort Key1:=Range("I1"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False

End Sub


where the range is read from some other cell on the spreadsheet. so the
macro reads what is in the cell telling it what range to sort, and then
enters that in the Range("").Select area of the macro.

Otherwise I have to create a separate macro for every area that might
possibly apply. I'd like to create an intelligent macro that I tell
what range to sort, or delete, or copy, or paste, etc, whatever I want
to happen with the range of cells I select.

Any ideas?

Thx


--
tx12345
------------------------------------------------------------------------
tx12345's Profile: http://www.excelforum.com/member.php...o&userid=24776
View this thread: http://www.excelforum.com/showthread...hreadid=495872



tx12345

Allowing for variable cell reference in macro
 

nothing like a simple solution. many thanks!


--
tx12345
------------------------------------------------------------------------
tx12345's Profile: http://www.excelforum.com/member.php...o&userid=24776
View this thread: http://www.excelforum.com/showthread...hreadid=495872



All times are GMT +1. The time now is 02:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com