Loading data using Dim stmt

sam99car

New Member
Joined
May 20, 2002
Messages
19
Hello,

My problem is-I am trying to load data from wksht 1. The data starts at I3 (date format that displays only Jan-03), J3 (as Feb-03), K3(Mar-03)...

Below is what I did:

Dim vdate As String
Dim x As Integer

' 12 is how many months to forecast
Dim vMonth(12) As String

Sheets(1).Select
For x = 1 To 12
vMonth(x) = Cells(8 + x, 3)
Next x

' Test if loaded
vdate = vMonth(6)
MsgBox vdate

Sheets(2).Select

Once it's loaded I will be using this to compare to sheet2.

Thanks in advance.

-sam.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

XL-Dennis

Well-known Member
Joined
Jul 27, 2002
Messages
1,920
sam,

Following code will
- read all data in range("C9:C20") and
- display the item 6, i e June in a msgbox

<pre>
Sub test()
Dim wsSheet As Worksheet
Dim rnMonth As Range
Dim vaMonth As Variant

Set wsSheet = ThisWorkbook.Worksheets("Blad1")

With wsSheet
Set rnMonth = .Range("C9:C20")
End With

vaMonth = rnMonth.Value

MsgBox vaMonth(6, 1)

'.....Your code
Sheets(2).Select
End Sub
</pre>

HTH,
Dennis
 
Upvote 0

sam99car

New Member
Joined
May 20, 2002
Messages
19
Hello Dennis,

Thank you for your response, unfortunately I get a "Subscript out of range" at this line:

MsgBox vaMonth(6, 1)

But, I will have to investigate your technique(range and variant).

-sam
 
Upvote 0

XL-Dennis

Well-known Member
Joined
Jul 27, 2002
Messages
1,920
sam99car,

Funny, since I tested it before publishing it I was a little bit surprised that You was forced to flip the numbers...

In what version of XL did this happend and how do the final procedure looks like?

Kind regards,
Dennis
 
Upvote 0

sam99car

New Member
Joined
May 20, 2002
Messages
19
Hello Dennis,

Sorry-i've been busy...

Well I was trying to load the data from I3,J3,K3,L3...("read" a row) and I noticed that your example was reading down a column-so, I tried flipping the numbers. (Still don't know why my original version didn't work)

I am using excel 97-(can't afford the newer versions you know! :) Plus if it works why change.)

Thank you very much for your help.

I will have another question but I'm going to keep trying first...
 
Upvote 0

Forum statistics

Threads
1,190,646
Messages
5,982,114
Members
439,756
Latest member
alice128

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
Top