Results 1 to 1 of 1

Thread: converting vb code to vba in excel to run as a macro.

  1. #1
    New Member
    Join Date
    Jun 12
    Posts
    9

    converting vb code to vba in excel to run as a macro.

    Hi, I am very new to VBA. I need a help on converting the VB code to VBA code. In vb, I am filtering a datagrid view to highlight the cells if the cells contain the time greater than 3:30 and less than 20:00.I have attached a excel file for which the code should reflect. And also I have pasted the code used in vb to highlight the cells in datagridview.Please remember the code below works for any number of records in the datagrid view.E.g. Today there might be 10 rows and 10 columns in a datagrid while tomorrow there might be 12 rows or 12 columns in datagrid - To keep it simple it should work for any number of rows and columns rather than being fixed .
    Please help me in providing a new VBA code or converting the below vb code to vba.


    Code:
    Dim colCount as Integer = DGV.Columns.Count
    
    If colCount > 1 Then
    
    Dim startDate As Date = Date.ToDay.Add(New TimeSpan(3, 30, 0))
    
    Dim endDate As Date = Date.ToDay.Add(New TimeSpan(20, 0, 0))
    
    Dim cellValue As String, cellDate As Date
    
    For i As Integer = 1 To colCount - 1
    
    For Each row As DataGridViewRow In DGV.Rows
    
    cellValue = row.Cells(i).Value.ToString
    
    If Date.TryParse(cellValue, cellDate) Then
    
    If cellDate > startDate AndAlso cellDate < endDate Then
    
    row.Cells(i).Style.BackColor = Color.LightYellow
    
    End If
    
    End If
    
    Next
    
    Next
    
    End If
    Attached Images Attached Images  

Posting Permissions

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