PDA

View Full Version : VBA Code to read the structure & data of an excel sheet having merged rows & columns



alam
04-24-2007, 09:58 PM
Hi ,

I am currently working on an excel sheet . That excel sheet will contain merged cells rowwise and columnwise but not both.

I have to determine the structure as well the data of the excel file . Can any one tell me the code for doing it . I am doing my coding in visual basic text editor of excel file. so please send the appropriate code.

Currently i have developed the macro for reading 10 unmerged rows & columns.Here it is :-



Sub proRead()
'Taufiq Alam Khan

Dim Selectedvalue As Double
Dim Counter As Double
Dim Row As Double
Row = 0

Range("A1").Select

Do Until Row = 10
For Counter = 1 To 10
Selectedvalue = Selection.Value
'Selection.Value = 0
Selection.Offset(0, 1).Select
Next
Selection.Offset(1, -10).Select
Row = Row + 1
Loop

Range("A1").Select

End Sub

This will only read the first 10 columns and first 10 rows of the excel file having unmerged cells . if this code is used for merged cells then it will throw an exception . so kindly suggest some solution for it .............

Aussiebear
04-24-2007, 10:17 PM
well I'd suggest you don't merge cells. But you probably didn't want to hear that.

JimmyTheHand
04-25-2007, 07:34 AM
Hi Alam, welcome to VBAX!

I'm afraid it's not very clear what your goal is. Could you explain a bit more?
What do you mean by determining the structure? And data? I'm really confused :confused:. It would be best if you could upload a sample workbook (see Manage Attachments button).

:devil2: To say something useful, for a change, I'd suggest using Long type variables in loops, like
Dim Counter As Long
Dim Row As Long

also, your code gets nice and more readable if you use VBA tags around it (see the green rectangle with VBA inscription above the post editor window).

Jimmy