Consulting

Results 1 to 11 of 11

Thread: Vba to insert text in range of cells

  1. #1

    Vba to insert text in range of cells

    I need to insert the below text in a range of 5 cells in a workbook that contains 6 sheets

    Cell X2 : FIT
    Cell X3 : WEB TO
    Cell X4 : TO
    Cell X5 : TA
    Cell X6 : IDS
    Cell X7 : OWN

    Thanks a lot for the help

  2. #2
    VBAX Newbie
    Joined
    Feb 2016
    Posts
    4
    Location
    The best way I found to see how the VBA might look is to record a macro and manually do it once. Then you can modify the new macro.
    Now where is this information stored? is this going to be inserted in every sheet? or just one sheet?

  3. #3
    the text is not stored anywhere...i need this text to be inserted in the range X2:X7 in each sheet

  4. #4
    VBAX Newbie
    Joined
    Feb 2016
    Posts
    4
    Location
    here is a dirty sample. you could make this better if you made the words into constant variables and then looped through the spreadsheets.

    Range("W2").Select
        ActiveCell.FormulaR1C1 = "Fit"
        Range("W3").Select
        ActiveCell.FormulaR1C1 = "Web To"
        Range("W4").Select
        ActiveCell.FormulaR1C1 = "To"
        Range("W5").Select
        ActiveCell.FormulaR1C1 = "TA"
        Range("W6").Select
        ActiveCell.FormulaR1C1 = "IDS"
        Range("W7").Select
        ActiveCell.FormulaR1C1 = "OWN"
        Range("W2:W7").Select
        Selection.Copy
        Sheets("Sheet1").Select
        ActiveWindow.SmallScroll ToRight:=12
        Range("X2").Select
        ActiveSheet.Paste
        Sheets("Sheet2").Select
        ActiveWindow.SmallScroll ToRight:=11
        Range("X2").Select
        ActiveSheet.Paste
        Sheets("Sheet3").Select
        ActiveWindow.SmallScroll ToRight:=12
        Range("X2").Select
        ActiveSheet.Paste
        Sheets("Sheet4").Select
        ActiveWindow.SmallScroll ToRight:=10
        Range("W2").Select
        ActiveSheet.Paste
        Sheets("Sheet5").Select
        ActiveWindow.SmallScroll ToRight:=11
        Range("X2").Select
        ActiveSheet.Paste
    Last edited by Aussiebear; 04-21-2023 at 07:01 PM. Reason: Adjusted the code tags

  5. #5
    thank you, will try and let you know

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Sub SamT()
    Dim Sht As Worksheet
    For each Sht in Worksheets
    Sht.Range.("X2") = Array("FIT", "WEB TO", "TO", "TA", "IDS", "OWN")
    Next'
    End Sub
    Last edited by Aussiebear; 04-21-2023 at 07:01 PM. Reason: Added code tags
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    SamT hello,
    thank you for the code.
    when i run it comes out the error:

    Compile error:
    Expected: identifier or bracketed expression

  8. #8
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Sub SamT()
    Dim Temp
    Dim Sht As Worksheet
    For Each Sht In Worksheets
    Temp = Array("FIT", "WEB TO", "TO", "TA", "IDS", "OWN")
    
    Sht.Range("X2").Resize(6) = Application.Transpose(Temp)
    Next '
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  9. #9
    Thank you SamT, works fine now

  10. #10
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645

  11. #11
    hello snb, what do you mean???

Posting Permissions

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