+ Reply to Thread
Results 1 to 5 of 5

VBA Code not working

  1. #1
    Registered User
    Join Date
    07-29-2013
    Location
    India
    MS-Off Ver
    Excel 2002
    Posts
    53

    VBA Code not working

    Dear Experts,

    My sincere thanks for taking your time for this. This will help me learn more.

    I have learned VBA Coding recently and trying to write a code for a need.

    Need is --

    Depending upon the value in cell B2, values in c3, c4 and c5 should change automatically.
    B2 is in drop down list.
    It should by dynamic, whenever "B2" changes, C, c4, c5 should change

    I wrote the code in the "This Workbook" in the VBA window. Unfortunately, the code is not working. Can you please help me understand where did I make the mistake here?

    Code is -

    Private Sub WorkSheet_Change(ByVal Target As Range)

    Whrosksheets("Sheet1").Select
    Whrosksheets("Sheet1").Range("B2").Value = Reason
    If Target.Address = "$B$2" Then
    If Reason = "Magesh" Then
    Whrosksheets("Sheet1").Range("C3").Value = Whrosksheets("Sheet1").Range("J3").Value
    Whrosksheets("Sheet1").Range("C4").Value = Whrosksheets("Sheet1").Range("J4").Value
    Whrosksheets("Sheet1").Range("C5").Value = Whrosksheets("Sheet1").Range("J5").Value
    Else
    If Reason = "Suresh" Then
    Whrosksheets("Sheet1").Range("C3").Value = Whrosksheets("Sheet1").Range("K3").Value
    Whrosksheets("Sheet1").Range("C4").Value = Whrosksheets("Sheet1").Range("K4").Value
    Whrosksheets("Sheet1").Range("C5").Value = Whrosksheets("Sheet1").Range("K5").Value
    Else
    If Reason = "Ramesh" Then
    Whrosksheets("Sheet1").Range("C3").Value = Whrosksheets("Sheet1").Range("L3").Value
    Whrosksheets("Sheet1").Range("C4").Value = Whrosksheets("Sheet1").Range("L4").Value
    Whrosksheets("Sheet1").Range("C5").Value = Whrosksheets("Sheet1").Range("L5").Value
    Else
    End If

    End If

    End If
    Else
    End If
    End Sub

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,645

    Re: VBA Code not working

    Typo:
    Whrosksheets

    try to replace with
    Worksheets
    Quang PT

  3. #3
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,645

    Re: VBA Code not working

    Not only typo, but also wrong variable "Reason"
    HTML Code: 

  4. #4
    Registered User
    Join Date
    07-29-2013
    Location
    India
    MS-Off Ver
    Excel 2002
    Posts
    53

    Re: VBA Code not working

    Fantastic, its one of my mistake. After removing type error, I pasted the codes in specific worksheet window, and it started working. My sincere thanks to you!

  5. #5
    Registered User
    Join Date
    07-29-2013
    Location
    India
    MS-Off Ver
    Excel 2002
    Posts
    53

    Re: VBA Code not working

    Thanks again!. Great help for learning!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA code not working with Excel 365 But working in 2010
    By hudson andrew in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-11-2022, 11:56 AM
  2. [SOLVED] Trouble with a VB code (both working and not working)
    By Jaysama in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-13-2021, 03:32 PM
  3. [SOLVED] Pattern Building VBA Code - Working code, would like to use cleaner code
    By Benisato in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-10-2015, 03:05 PM
  4. [SOLVED] Vba code working in workbook module but not working from personal.xlb
    By satputenandkumar0 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-19-2014, 05:47 AM
  5. Replies: 1
    Last Post: 11-13-2013, 10:28 AM
  6. [SOLVED] VBA Code (colums to row, autofill) stop working in row 294 when new cable code appear
    By sknifseht in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-29-2012, 05:27 AM
  7. Code for email alerts from excel isn't working, wrong code possibly?
    By jessthorogood in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2012, 01:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1