Help with checking cells and entering data from VBA to cells

kharmaz

New Member
Joined
Oct 16, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello all!

I haven't been working in VBA in a LONG time and trying some simple checks in a workbook and making changes. When I had my first part of the code in, it was fine. When I added the Subject line string creation, I started getting errors. Any help please?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim ST_1 As String
    Dim ST_2 As String
    Dim ST_3 As String
    Dim ST_4 As String
    Dim ST_5 As String
    Dim ST_6 As String
    
    Dim Object As String
    Dim Operation As String
    Dim Location As String
    Dim Reference As String
    Dim Job As String
    Dim Spacer As String
    Dim Wording As String

    Spacer = " - "
    Wording = Spacer & "Status Update" & Spacer
    
'ETA Update, Show Times, Special Update

    If Target.Column = 3 And Target.Row = 14 Then
        If Target.Value = "ETA Update" Then
            Application.Rows("36:47").Select
            Application.Selection.EntireRow.Hidden = True
        ElseIf Target.Value = "Show Times" Then
            Application.Rows("36:47").Select
            Application.Selection.EntireRow.Hidden = False
        ElseIf Target.Value = "Special Update" Then
            Application.Rows("36:47").Select
            Application.Selection.EntireRow.Hidden = True
        End If
    End If

' Beginning of Subject Line Creation
    
    ST_1 = "Update" & Spacer & Operation & Spacer & Object & Spacer & Location & Spacer & Reference & Spacer & Job
    
    If Range(B5).Value = "ABC" Then
        ST_1 = Reference & Spacer & Object & Spacer & Location & IrvingWording & Job
    ElseIf Range(B5).Value = "123" Then
        ST_1 = Reference & Spacer & "Update" & Spacer & Operation & Spacer & Object & Spacer & Location & Spacer & Job
    ElseIf Range(B5).Value = "A1B2" Then
        If Range(B6).Value = "them" Then
            ST_1 = "Update" & Spacer & Operation & Spacer & Object & Spacer & Location & Spacer & Reference & " / " & Range(B6).Value & Spacer & Job
        End If
     End If
            
    Range(I26) = ST1

    
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Welcome to the MrExcel board!

I haven't tested your code but from a quick look ..

Your ranges are not specified correctly. Example
VBA Code:
If Range(B5).Value = "ABC" Then
should be
VBA Code:
If Range("B5").Value = "ABC" Then


Also, I am not sure if it would be affecting this particular code but 'Object' is not a good variable name as that word has its own special meaning in the vba language. You will notice in your code in post 1 that it is coloured blue along with other vba 'special' words.
 
Upvote 0
Along with Peter's comments, you have declared these variables
VBA Code:
   Dim Object As String
    Dim Operation As String
    Dim Location As String
    Dim Reference As String
    Dim Job As String
but you have not given them any value.
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,694
Members
449,117
Latest member
Aaagu

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