+ Reply to Thread
Results 1 to 4 of 4

VBA IF Problem (Fairly Simple)

  1. #1
    Registered User
    Join Date
    01-08-2015
    Location
    Dublin
    MS-Off Ver
    Excel 2010
    Posts
    18

    VBA IF Problem (Fairly Simple)

    Hello everyone I'm fairly new and would love to start using Excel VBA properly and well. Anyway my first problem is trying to information from 5 workbooks onto one (Ive simplified this to just two.), I have already done a lot of the hard work (I hope), its just an IF statement which is annoying me. Do not worry about the file names, I have had to edit them as I am currently on an internship for a big company which I'm sure wouldnt want the name of their personal files broadcast on the internet.

    Sub PasteIt()

    Dim u As Workbook
    Dim z As Workbook

    Set u = Workbooks.Open("Y:file1.xlsx")
    Set z = Workbooks("Main file.xlsm")

    Workbooks("file1.xlsx").Activate
    If Range("B4:B500000").Value Like Date Then
    ActiveCell.EntireRow.Select
    Selection.Copy
    End If

    Workbooks("Main file.xlsx").Select
    Range("A65536").End(xlUp)(2, 1).Select
    ActiveSheet.Paste

    End Sub

    Bold and Italics is a mismatch error, any way I can fix this please anyone?
    Last edited by LewisLonsdale; 01-08-2015 at 12:16 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,501

    Re: VBA IF Problem (Fairly Simple)

    You can't compare an entire range (a subset of column B). You'd need to loop through the range and compare each cell.

    There's not much point setting workbook variables if you still refer to the workbook names.

    Please use Code Tags, and there's no bold or italics shown.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    01-08-2015
    Location
    Dublin
    MS-Off Ver
    Excel 2010
    Posts
    18

    Re: VBA IF Problem (Fairly Simple)

    I've done this

    Dim rng As Range, cell As Range
    Set rng = Range("B4:B1000")
    For Each cell In rng
    Next cell

    Workbooks("xxxxx.xlsx").Activate
    If rng.Value Like Date Then
    ActiveCell.EntireRow.Select
    Selection.Copy
    End If

    Why isnt it working? (Bold and Italics "mismatch error")

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,501

    Re: VBA IF Problem (Fairly Simple)

    You need the loop to be around the stuff you want to do. And you need to check the cell (For Each Cell ...)

    Please Login or Register  to view this content.

    Regards, TMS

+ 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. Help, Formula Won't Carry Through
    By dyzfunctioned in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-25-2013, 01:50 PM
  2. Fairly Simple Formula Question- Any help?
    By Hizuremai in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-03-2012, 12:22 PM
  3. Fairly simple, but need help.
    By littlcor in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-23-2006, 03:02 AM
  4. [SOLVED] HELLLP!!!! This should be fairly simple I would think!
    By InfinityDesigns in forum Excel General
    Replies: 7
    Last Post: 06-18-2005, 11:05 PM

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