Item Selection within a Macro

cstewart

New Member
Joined
Feb 19, 2011
Messages
6
I am a teacher and I set up a tool to take exported student test responses and turn them into a table with "offset".

I have set up macros for everything but selecting the number of questions to copy. "Shift + arrow" takes me to the end of the record (of 50) but most test have less than that.

I have tried using "relative reference" and a cell value in the macro steps, but i haven't been successful.

I have spent a lot of time looking for an answer, but I don't even know the right words to use. Could somebody tell me where to look? Thanks.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
There's a variety of methods within macros to find the last used cell in a column, a range, the whole worksheet, or whatever.

Could you perhaps be a bit more specific about just what you're looking for?
 
Upvote 0
I will try, I made a table to take data (student test item responses) from a few columns and turn it into a table.

The table has 50+ columns. But I need to take different numbers of columns based on the number of questions in the test.

I have tried Shift+right, but I number of items changes and Shift+right always takes me to the end of the table.

Even if you could just get me in the right direction by telling me some of the terms I could look for on-line, thanks.
 
Upvote 0
I usually assign this to a variable in vba:

Code:
Application.Counta(Range("A:A"))
It counts the number of non-blank cells in column A. If you have a header row, just subtract 1 from the variable.

Oops, just saw your last post and realized this won't help you.
 
Upvote 0
This is the formula that I entered to make the table from the columns.

"=OFFSET($E$2,(MAX($D$2:$D$50)*(ROW()-ROW(W$3)))+(COLUMN()-COLUMN($K4)),0,1,1)"

It always produces a "0" or a "1", so even if a column is unused, it will have a number in it.
 
Upvote 0
Is there a way to just tell the macro to start at the selected cell and select x number more cells to the right? Then I could just use a cell value for x?
 
Upvote 0
Is there a way to just tell the macro to start at the selected cell and select x number more cells to the right? Then I could just use a cell value for x?

Try this when cell A1 contains the number of columns you want to select in row 3:
Code:
Dim i As Integer
x = Cells(1, 1)
Range(Cells(3, 1), Cells(3, x)).Select
 
Upvote 0
Is there a way to just tell the macro to start at the selected cell and select x number more cells to the right? Then I could just use a cell value for x?
With any selected cell, this line in your macro will retain your selection and select x more cells to the right
Code:
'say x = 3
Selection.Resize(, x + 1).Select
although I can't really see why you should want to do this.

Generally there's no need to select cells or ranges to do further operations or analysis on them. Usually their location is identified in other ways.
 
Upvote 0

Forum statistics

Threads
1,215,493
Messages
6,125,131
Members
449,206
Latest member
burgsrus

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