Pls help on VBA code: Table to list etc

mrchonginhk

Well-known Member
Joined
Dec 3, 2004
Messages
679
Hi I have a table like this
VBAAssignment1.xls
ABCDE
1Q2
2Col1Col2Col3Col4
3Row11234
4Row25678
5Row39101112
6Row413141516
7Row517181920
Q2


Then, I need to write a FUNCTION called
Tableonly that returns a table as range without extraneous emoty rows and column. But, if user clicks a cell outside table, return only cell where user has clicked. Hints from my boss: Use COUNTA and range.EntireRow.

Then using above write program that selects only data from table (Bosss say use range.size method)

Then write another program select only col heading
Then write another select only row headings

Hence, write a program converting the table in a list. ie the table above should becomes:-
VBAAssignment1.xls
GHIJ
6Row1Col11
7Row2Col15
8Row3Col19
9Row4Col113
10Row5Col117
11Row1Col22
12Row2Col26
13Row3Col210
14Row4Col214
15Row5Col218
16Row1Col33
17Row2Col37
18Row3Col311
19Row4Col315
20Row5Col319
21Row1Col44
22Row2Col48
23Row3Col412
24Row4Col416
25Row5Col420
Q2


Pls help. Any one part will help ... Thanks.

:rolleyes:
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Forget to tell...

The numbers 1,2,3, 4 etc in the 1st table should be fixed values instead of formula.

Thanks.
 
Upvote 0
Forget to tell...

The numbers 1,2,3, 4 etc in the 1st table should be fixed values instead of formula.

Thanks.
 
Upvote 0
Give this a whirl:
Book1
ABCDE
1
2Col1Col2Col3Col4
3Row11234
4Row25678
5Row39101112
6Row413141516
7Row517181920
8Row1Col11
9Row2Col15
10Row3Col19
11Row4Col113
12Row5Col117
13Row1Col22
14Row2Col26
15Row3Col210
16Row4Col214
17Row5Col218
18Row1Col33
19Row2Col37
20Row3Col311
21Row4Col315
22Row5Col319
23Row1Col44
24Row2Col48
25Row3Col412
26Row4Col416
27Row5Col420
Sheet1


And the code:<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> TableOnly()<SPAN style="color:#00007F">Dim</SPAN> EndColumn<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN><SPAN style="color:#00007F">Dim</SPAN> EndRow<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN><SPAN style="color:#00007F">Dim</SPAN> ThisRow<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN><SPAN style="color:#00007F">Dim</SPAN> ThisColumn<SPAN style="color:#00007F">As</SPAN><SPAN style="color:#00007F">Long</SPAN><SPAN style="color:#00007F">Dim</SPAN> ThisCell<SPAN style="color:#00007F">As</SPAN> Range

    EndColumn = Range("IV2").End(xlToLeft).Column
    EndRow = Range("A65536").End(xlUp).Row
    <SPAN style="color:#00007F">For</SPAN> ThisColumn = Range("A2").End(xlToRight).Column<SPAN style="color:#00007F">To</SPAN><SPAN style="color:#00007F">End</SPAN>Column
        <SPAN style="color:#00007F">For</SPAN> ThisRow = Range("A1").End(xlDown).Row To EndRow
            <SPAN style="color:#00007F">Set</SPAN> ThisCell = Range("A65536").End(xlUp).Offset(1)
            ThisCell.Value = Cells(ThisRow, 1)
            ThisCell.Offset(, 1).Value = Cells(2, ThisColumn)
            ThisCell.Offset(, 2).Value = Cells(ThisRow, ThisColumn)
        <SPAN style="color:#00007F">Next</SPAN> ThisRow
    <SPAN style="color:#00007F">Next</SPAN> ThisColumn

End<SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
A function won't do the work for you. Think of a FUNCTION as being a math equation. A function will just spit out an answer for you, it won't do the work.
 
Upvote 0
Thx
Ok forget about formula....

I created a button and assign your code to it and then I select the range and click the button but nothing happen. Did I miss some step/s ?
 
Upvote 0
Sorry... it did work... !! Thanks.

Then, one final help are 3 small codes-

Write program that selects only data from original table (Bosss say use range.size method)

Then write another program select only col heading
Then write another select only row headings
 
Upvote 0

Forum statistics

Threads
1,215,420
Messages
6,124,803
Members
449,190
Latest member
cindykay

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