samanthareed2012

New Member
Joined
May 2, 2014
Messages
9
Hi All,

I’m a newbie to VBA, but I have managed (with the help of some coworkers and Google) to put together a code to make a table and fill the cells with appropriate testing information.

The code I have written has an if statement and it’s supposed to go to a block and then resume where it left off, but it just skips cells that I need it to pull data from. Please help! Thank you in advance for all your help!


My code is below:


Code:
Dim c As Range
Dim variable As String
Dim VarDes As String
Dim DataType As String
Dim ResponseType As String
Dim wordTable As Object
Dim wordRange As Object
Dim wordDocument As Object

Dim VarID As String
Dim Des As String
Dim datatypevalue As String
Dim Section As String
Dim ResponseOptions As String
Dim resopvalue As String
Dim Dec As String
Dim DecVal As String


Dim i As Integer
Dim wordCount As Integer
Dim goToBlock As Integer
Dim numCells As Long

'Initialize counter for the word table
wordCount = 1
'Counter for Excel worksheet
For i = 1 To numCells
variable = "A" & CStr(i)
Range(variable).Select
VarID = Range(variable).Value
VarDes = "C" & CStr(i)
Des = Range(VarDes).Value
Dec = "U" & CStr(i)
DecVal = Range(Dec).Value
DataType = "T" & CStr(i)
datatypevalue = Range(DataType).Value
ResponseType = "N" & CStr(i)
datatypevalue = Range(ResponseType).Value
Section = "F" & CStr(i)
ResponseOptions = "P" & CStr(i)
resopvalue = Range(ResponseOptions).Value
If InStr(Range(ResponseType).Value, "single-select") Then
    goToBlock = 1


ElseIf InStr(Range(DataType).Value, "ST") Then
wordTable.Rows.Add
wordCount = wordCount + 1
wordTable.Cell(wordCount, 1).Range.Text = wordCount - 1
wordTable.Cell(wordCount, 2).Range.Text = VarID
wordTable.Cell(wordCount, 3).Range.Text = Des
wordTable.Cell(wordCount, 4).Range.Text = "Enter 3999 numeric, character, and special character values"
wordTable.Cell(wordCount, 5).Range.Text = "Input Accepted"

1:
ElseIf InStr(Range(ResponseType).Value, "single-select") Then
wordTable.Rows.Add
wordCount = wordCount + 1
wordTable.Cell(wordCount, 1).Range.Text = wordCount - 1
wordTable.Cell(wordCount, 2).Range.Text = VarID
wordTable.Cell(wordCount, 3).Range.Text = Des
wordTable.Cell(wordCount, 4).Range.Text = "verify all drop down values are present:" & Chr(10) & resopvalue
wordTable.Cell(wordCount, 5).Range.Text = "Values present"
Resume Next
 

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.
Resume Next is strictly for error handling. If you had an error, you send your code to a section that's outside the normal code (via a GoTo label). Within that section, you handle the error, and resume on the line where you first sent it to. On Error and Resume statements go hand in hand.

Barring a few execution inefficiencies - I think this is what your If block should look like:

Code:
wordTable.Rows.AddwordCount = wordCount + 1
wordTable.Cell(wordCount, 1).Range.Text = wordCount - 1
wordTable.Cell(wordCount, 2).Range.Text = VarID
wordTable.Cell(wordCount, 3).Range.Text = Des


If InStr(Range(ResponseType).Value, "single-select") Then
  
  wordTable.Cell(wordCount, 4).Range.Text = "verify all drop down values are present:" & Chr(10) & resopvalue
  wordTable.Cell(wordCount, 5).Range.Text = "Values present"


ElseIf InStr(Range(DataType).Value, "ST") Then


  wordTable.Cell(wordCount, 4).Range.Text = "Enter 3999 numeric, character, and special character values"
  wordTable.Cell(wordCount, 5).Range.Text = "Input Accepted"


End If
 
Upvote 0
Oh! Well it makes sense that the Resume Next wouldn't work then.

Thank you for clarifying and thanks for the edits. I'll try them out.
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

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