Hello,
I posted a thread earlier on this particular project I'm working on. Most issues have been solved and the program is sort of working. It's not encountering errors that stop the macro like before. The macro runs but i think the issue now is with the If-Then-ElseIf-Then-Else statement (see code below).
Background:
This macro copies cells from another workbook (I'll call it Copy workbook for future reference) based on 3 string values in column "E" which are "Vertical, "Angle", and "n/a". It Then pastes cells into the workbook with the macro (call it Paste workbook). I'll explain with an example below. (Sorry about the formatting. Many columns are blank because their data isn't relevant to the example.)
Copy from the Copy Workbook:
Column A B C D ...... E ........... K ...... L
Row 1 (Headers)
Row 2 .............. "Vertical" ... 33.3 ... 3.3
Row 3 ................ "Angle" .... 22.2 ... 2.2
Row 4 ..................."n/a" ..... 11.1 ... 1.1
Paste to the Paste Workbook:
Column A B C .... D ...... E ........ I ....... J ........ N ....... O
Row 1 (Headers)
Row 2 (Sub Headers)
Row 3 ............ 33.3 ... 3.3 ..... 22.2 ... 2.2 ..... 11.1 ... 1.1
If column E in the Copy Workbook says "Vertical" the data is pasted to columns D & E in the Paste Workbook. If it's "Angle" the data is pasted to columns I & J. If it's "n/a" the data is pasted to columns N & O. I hope that's clear.
Here is the code:
The Issue:
The issue is that ALL data is being pasted to columns N & O, which should only have "n/a" data. I went through debug mode and found that the first two If and ElseIf lines of code are being skipped so everything goes to the Else statement at the end, which of course pastes all the data into columns N & O. I guess the macro isn't noticing the string values "Vertical" and "Angle" in column E in the Copy Workbook? The Copy Workbook uses data validation in column E so the user recording data must select between the 3 options ("Vertical", "Angle", and "n/a") in a drop down list. I checked out column E in the Copy Workbook and there are no issue with spelling/capitalization. Maybe the fix is easy and I'm not seeing it.
Thanks for your help. It's all been great so far.
-Nick
I posted a thread earlier on this particular project I'm working on. Most issues have been solved and the program is sort of working. It's not encountering errors that stop the macro like before. The macro runs but i think the issue now is with the If-Then-ElseIf-Then-Else statement (see code below).
Background:
This macro copies cells from another workbook (I'll call it Copy workbook for future reference) based on 3 string values in column "E" which are "Vertical, "Angle", and "n/a". It Then pastes cells into the workbook with the macro (call it Paste workbook). I'll explain with an example below. (Sorry about the formatting. Many columns are blank because their data isn't relevant to the example.)
Copy from the Copy Workbook:
Column A B C D ...... E ........... K ...... L
Row 1 (Headers)
Row 2 .............. "Vertical" ... 33.3 ... 3.3
Row 3 ................ "Angle" .... 22.2 ... 2.2
Row 4 ..................."n/a" ..... 11.1 ... 1.1
Paste to the Paste Workbook:
Column A B C .... D ...... E ........ I ....... J ........ N ....... O
Row 1 (Headers)
Row 2 (Sub Headers)
Row 3 ............ 33.3 ... 3.3 ..... 22.2 ... 2.2 ..... 11.1 ... 1.1
If column E in the Copy Workbook says "Vertical" the data is pasted to columns D & E in the Paste Workbook. If it's "Angle" the data is pasted to columns I & J. If it's "n/a" the data is pasted to columns N & O. I hope that's clear.
Here is the code:
Code:
Option Explicit
Sub GetData()
Dim wsPasteTo As Worksheet, wbDATA As Workbook
Dim NextRow As Long, LastRow As Long, i As Long
Set wsPasteTo = ThisWorkbook.Sheets("ACP")
NextRow = wsPasteTo.Range("A" & Rows.Count).End(xlUp).Row + 2
Set wbDATA = Workbooks.Open("\\cmicro.com\Shares\Amb\Amb-Probes\DataLogs\CQS-03-033-2012 Coax Shelf Cut Log R2.6.xlsm", ReadOnly:=True)
Application.ScreenUpdating = False
With wbDATA.Sheets("ACP")
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
For i = 2 To LastRow
If Cells(i, "E") = "Angle" Then
.Range("K2:L" & LastRow).Copy
wsPasteTo.Range("I" & NextRow).PasteSpecial xlPasteValues
ElseIf Cells(i, "E") = "Vertical" Then
.Range("K2:L" & LastRow).Copy
wsPasteTo.Range("D" & NextRow).PasteSpecial xlPasteValues
Else
.Range("K2:L" & LastRow).Copy
wsPasteTo.Range("N" & NextRow).PasteSpecial xlPasteValues
End If
Next i
End With
Application.ScreenUpdating = True
wbDATA.Close False
End Sub
The Issue:
The issue is that ALL data is being pasted to columns N & O, which should only have "n/a" data. I went through debug mode and found that the first two If and ElseIf lines of code are being skipped so everything goes to the Else statement at the end, which of course pastes all the data into columns N & O. I guess the macro isn't noticing the string values "Vertical" and "Angle" in column E in the Copy Workbook? The Copy Workbook uses data validation in column E so the user recording data must select between the 3 options ("Vertical", "Angle", and "n/a") in a drop down list. I checked out column E in the Copy Workbook and there are no issue with spelling/capitalization. Maybe the fix is easy and I'm not seeing it.
Thanks for your help. It's all been great so far.
-Nick
Last edited: