If Statements

coachbart

New Member
Joined
Aug 26, 2011
Messages
7
I am trying to use an IF statment in VBS to determine if the value contained in a specific cell on "data" excel sheet matches as a known value. If it does then the data in the adjancent cells are copied and pasted into a cell in the "report" excel sheet. If no, the the default values of zero are entered into the cell in the "report" excel sheet. The problem is that the macro is not going th the next IF statement if the first IF statement is true. Here is a sample of the code:

iRow = 8
var5514a = 0
var5514d = 0
var9071a = 0
var9071d = 0
var9072a = 0
var9072d = 0

Do

Windows(dummy & ".xls").Activate
If Application.Cells(iRow, 3).Value = "5514" Then
var5514a = Application.Cells(iRow, 4).Value
var5514d = Application.Cells(iRow, 5).Value + Application.Cells(iRow, 6).Value
Windows("Ongoing Tracking - Dev.v3.xlsm").Activate
Application.Cells(iLine, 3).Value = var5514a
Application.Cells(iLine, 4).Value = var5514d

End If

Windows("Ongoing Tracking - Dev.v3.xlsm").Activate
Application.Cells(iLine, 3).Value = var5514a
Application.Cells(iLine, 4).Value = var5514d

Windows(dummy & ".xls").Activate
If Application.Cells(iRow, 3).Value = "9071" Then
var9071a = Application.Cells(iRow, 4).Value
var9071d = Application.Cells(iRow, 5).Value + Application.Cells(iRow, 6).Value
Windows("Ongoing Tracking - Dev.v3.xlsm").Activate
Application.Cells(iLine, 7).Value = var9071a
Application.Cells(iLine, 8).Value = var9071d

End If

Windows("Ongoing Tracking - Dev.v3.xlsm").Activate
Application.Cells(iLine, 7).Value = var9071a
Application.Cells(iLine, 8).Value = var9071d
Windows(dummy & ".xls").Activate

If Application.Cells(iRow, 3).Value = "9072" Then
var9072a = Application.Cells(iRow, 4).Value
var9072d = Application.Cells(iRow, 5).Value + Application.Cells(iRow, 6).Value
Windows("Ongoing Tracking - Dev.v3.xlsm").Activate
Application.Cells(iLine, 11).Value = var9072a
Application.Cells(iLine, 12).Value = var9072d

End If
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try something like this (not tested).
I don't know where you are setting iRow and iLine.

<font face=Courier New>    <SPAN style="color:#00007F">Dim</SPAN> wbDummy <SPAN style="color:#00007F">As</SPAN> Workbook, wbTrack <SPAN style="color:#00007F">As</SPAN> Workbook<br>    <SPAN style="color:#00007F">Dim</SPAN> wsData <SPAN style="color:#00007F">As</SPAN> Worksheet, wsReport <SPAN style="color:#00007F">As</SPAN> Worksheet<br>    <SPAN style="color:#00007F">Dim</SPAN> col    <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><br>    <SPAN style="color:#00007F">Set</SPAN> wbDummy = Windows(dummy & ".xls")<br>    <SPAN style="color:#00007F">Set</SPAN> wbTrack = Windows("Ongoing Tracking - Dev.v3.xlsm")<br><br>    <SPAN style="color:#00007F">Set</SPAN> wsData = wbDummy.Sheets("data")<br>    <SPAN style="color:#00007F">Set</SPAN> wsReport = wbTrack.Sheets("Report")<br><br>    <SPAN style="color:#00007F">Do</SPAN><br>        col = 0<br>        <SPAN style="color:#00007F">Select</SPAN> <SPAN style="color:#00007F">Case</SPAN> wsData.Cells(iRow, 3).Value<br>            <SPAN style="color:#00007F">Case</SPAN> 5514: col = 3<br>            <SPAN style="color:#00007F">Case</SPAN> 9017: col = 7<br>            <SPAN style="color:#00007F">Case</SPAN> 9072: col = 11<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Select</SPAN><br><br>        <SPAN style="color:#00007F">If</SPAN> col > 0 <SPAN style="color:#00007F">Then</SPAN><br>            wsReport.Cells(ILine, col).Value = wsData.Cells(iRow, 4).Value<br>            wsReport.Cells(ILine, col + 1).Value = wsData.Cells(iRow, 5).Value + wsData.Cells(iRow, 6).Value<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br></FONT>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,672
Members
452,937
Latest member
Bhg1984

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