+ Reply to Thread
Results 1 to 3 of 3

Macro that checks for divisibility of 2 and 3 for range of numbers

  1. #1
    Registered User
    Join Date
    02-05-2024
    Location
    USA
    MS-Off Ver
    2021
    Posts
    2

    Question Macro that checks for divisibility of 2 and 3 for range of numbers

    Column 1 is already set. Column 2 must check for divisibility of 2 and display "yes" if divisible and nothing if not. Same for column 3 checking for divisibility of 3. Here is what I have.

    Sub Divisible()

    'this macro determines if a number is divisible by 2 or 3

    For rowcounter = 1 To 100

    Cells(rowcounter, 1).Value = rowcounter 'column 1 has 1,2,3,...



    Next rowcounter

    End Sub

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,819

    Re: Macro that checks for divisibility of 2 and 3 for range of numbers

    If Cells(rowcounter, 1).Value Mod 2 = 0 then Cells(rowcounter, 2).Value ="True"
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    02-05-2024
    Location
    USA
    MS-Off Ver
    2021
    Posts
    2

    Re: Macro that checks for divisibility of 2 and 3 for range of numbers

    Thank you. Here is the code when I finished.

    Sub Divisible()

    'this macro determines if a number is divisible by 2 or 3



    For rowcounter = 1 To 100

    Cells(rowcounter, 1).Value = rowcounter

    If Cells(rowcounter, 1).Value Mod 2 = 0 Then
    Cells(rowcounter, 2).Value = "Yes"
    ElseIf Cells(rowcounter, 2).Value Mod 2 = 1 Then
    Cells(rowcounter, 2).Value = ""
    End If

    If Cells(rowcounter, 1).Value Mod 3 = 0 Then
    Cells(rowcounter, 3).Value = "Yes"
    ElseIf Cells(rowcounter, 3).Value Mod 3 = 1 Then
    Cells(rowcounter, 3).Value = ""
    End If

    Next rowcounter

    End Sub

+ 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. Replies: 10
    Last Post: 07-14-2015, 12:26 AM
  2. Replies: 0
    Last Post: 11-21-2014, 05:00 PM
  3. Macro button which checks for a value in certain range of cells per row?
    By Jake_Rex in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-10-2013, 11:24 AM
  4. macro that checks if the content of a given cell range exists in a Word file
    By Vogelmann in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-19-2012, 03:55 AM
  5. [SOLVED] Formula which checks whether a string is found in a range and checks 2 criteria
    By liranbo in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-30-2012, 05:28 PM
  6. formula using Divisibility test
    By kspeedy28 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2006, 03:20 AM
  7. Determining Divisibility
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 08-29-2005, 11:08 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