Hello all,
I am having a couple issues with a macro i created this week (already received help from this board once, and I appreciate it)...I am very new to this, and I realize the code is probably sloppy...if anyone could please help, any suggestions are welcomed.
My issues are as follows:
1. I used to just have the below code copied 7 times, to individually scan through the 7 sheets I need it to read. I did get it to work that way. It was inefficient and hard to manage, so I looked up some tutorials and tried to make it loop through the specified worksheets. I now keep receiving a type mismatch error (at the line below, colored green). Anyone have any idea what i'm doing wrong? " ++++" 's
2. In my Match function, i receive an error whenever it looks for a value in the sheet and it isn't there...this is to be expected, as some of these sheets are not going to have the attribute I am running the macro for. Is there any type of error handling that would work well for this, or is there some form of if statement i should be using, etc.? The line where I keep receiving this error is denoted with " **** " 's
3. Any other suggestions are appreciated-I'm not even sure in the regular code portion I used the "ws" variable correctly when calling up a worksheet.
THANKS SO MCUH FOR YOUR HELP!!!!
I am having a couple issues with a macro i created this week (already received help from this board once, and I appreciate it)...I am very new to this, and I realize the code is probably sloppy...if anyone could please help, any suggestions are welcomed.
My issues are as follows:
1. I used to just have the below code copied 7 times, to individually scan through the 7 sheets I need it to read. I did get it to work that way. It was inefficient and hard to manage, so I looked up some tutorials and tried to make it loop through the specified worksheets. I now keep receiving a type mismatch error (at the line below, colored green). Anyone have any idea what i'm doing wrong? " ++++" 's
2. In my Match function, i receive an error whenever it looks for a value in the sheet and it isn't there...this is to be expected, as some of these sheets are not going to have the attribute I am running the macro for. Is there any type of error handling that would work well for this, or is there some form of if statement i should be using, etc.? The line where I keep receiving this error is denoted with " **** " 's
3. Any other suggestions are appreciated-I'm not even sure in the regular code portion I used the "ws" variable correctly when calling up a worksheet.
THANKS SO MCUH FOR YOUR HELP!!!!
HTML:
Option Explicit
Sub test()
Dim ws As Worksheet, InputCells As Excel.Range, RowValue As Long, ColumnValue As Long, _
i As Long, j As Integer, K As Long, L As Integer, M As Integer, _
Count As Long, Str As String, Str2 As String, Str0 As String
Set InputCells = Application.InputBox(Prompt:="Select Attribute Name", _
Title:="Attribute", Type:=8)
RowValue = InputCells.Row
ColumnValue = InputCells.Column
For Each ws In ThisWorkbook.Worksheets
'++++++Mismatch error at next line...I need the macro to loop through only these tabs in this workbook!****
If ws.Name = "1A" Or "1B" Or "2A" Or "2B" Or "3" Or "4" Or "5" Then
'******When it cannot find a MATCH value in the sheet (next line below)
(every sheet does not have every attribute),
I need it to just disregard and continue to the next sheet...
I've tried different styles of error handling i found in a book,
but I cannot get it to work. Also, am I using the "Sheets(ws)" piece correctly?****
i = WorksheetFunction.Match(InputCells.Value, Sheets(ws).Range("A:A"), 0)
K = i + 1
Do Until IsEmpty(Sheets(ws).Cells(K + 2, 1).Value)
K = K + 1
Loop
i = i + 1
For i = i To K
If IsEmpty(Sheets(ws).Cells(i, 7).Value) Then Str2 = Str2
If Not IsEmpty(Sheets(ws).Cells(i, 7).Value) Then Str = Sheets(ws).Cells(i, 1).Value _
& " " & Application.Text(Sheets(ws).Cells(i, 7).Value, "$0;$(0);0")
If Not IsEmpty(Sheets(ws).Cells(i, 7).Value) Then Str2 = Str2 + ", " + Str
Next i
Str0 = "PMT " + ws.Name
Sheets("Test").Cells(RowValue + 1, ColumnValue) = Str0 + Str2
End If
Next ws
End Sub