Click here to Skip to main content
15,887,585 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Create Image from Panel Control Pin
Eddy Vluggen5-Oct-14 2:13
professionalEddy Vluggen5-Oct-14 2:13 
GeneralRe: Create Image from Panel Control Pin
gwittlock5-Oct-14 3:16
gwittlock5-Oct-14 3:16 
Questionvb Pin
Nishat Anwar27-Sep-14 6:41
Nishat Anwar27-Sep-14 6:41 
AnswerRe: vb Pin
Dave Kreskowiak27-Sep-14 6:47
mveDave Kreskowiak27-Sep-14 6:47 
QuestionRecommendations on VB.Net to C# code conversion tool Pin
Vipul Mehta26-Sep-14 10:28
Vipul Mehta26-Sep-14 10:28 
AnswerRe: Recommendations on VB.Net to C# code conversion tool Pin
Tim Carmichael26-Sep-14 11:24
Tim Carmichael26-Sep-14 11:24 
GeneralRe: Recommendations on VB.Net to C# code conversion tool Pin
Vipul Mehta27-Sep-14 3:21
Vipul Mehta27-Sep-14 3:21 
QuestionFormatting Excel from Access: How do I apply conditional formatting with a loop? Pin
Member 1111259726-Sep-14 7:29
Member 1111259726-Sep-14 7:29 
I have some code that moves data from an Access database into an Excel spreadsheet. I know that there are easier ways of doing this, but for my particular needs I have to have it moved this way.
The code goes through a query in Access and moves data into the spreadsheet with a loop. That part works just fine.

The problem is that I have to format the spreadsheet with this code. All of the different categories of data will be formatted differently. The piece I am looking at now is called "TheTO."

The code I have moves the data and then goes back and formats cells based on their content. It looks for the words in the cells to do this. The problem is that I will have to repeat this code for about 40 different phrases. That seems excessive to me. Also, if any of those phrases change at all, the code won't work.

I want to have the formatting happen during the loop. However, I don't know how to do that.

Here is the code. I am including one block of the code that is formatting the cells. There would be many, many more because the C.Value will be different every time.
TheTO = rs!to
oSheet.Cells(2, 1).Value = TheTO
TheSTOname = rs!STO
oSheet.Cells(3, 1).Value = TheSTOname
TheStaffName = rs!TeamName
oSheet.Cells(3, 2).Value = TheStaffName
theActDesc = rs!ActDesc
oSheet.Cells(3, 3).Value = theActDesc

rs.MoveNext

Do Until rs.EOF

    If rs!to = TheTO Then
        If rs!STO = TheSTOname Then
            If TheStaffName = rs!TeamName Then
                If theActDesc = rs!ActDesc Then
                    rs.MoveNext
                Else
                    theRow = theRow + 1
                    oSheet.Cells(theRow, 3).Value = rs!ActDesc
                    rs.MoveNext
                End If
            Else
                'theRow = theRow + 1
                oSheet.Cells(theRow, 2).Value = rs!TeamName
                TheStaffName = rs!TeamName
                
                rs.MoveNext
            End If
        Else
            theRow = theRow + 1
            oSheet.Cells(theRow, 1).Value = rs!STO
            TheSTOname = rs!STO
            TheStaffName = ""
            
            rs.MoveNext
        End If
    Else
        theRow = theRow + 1
        oSheet.Cells(theRow, 1).Value = rs!to
        TheTO = rs!to

        rs.MoveNext
    End If
skip:
Loop

iNumCols = IIf(w > 0, w, iNumCols)
'Format the header row as bold
With oSheet.Range("a1").Resize(1, iNumCols)
.Font.Bold = True
'Size the columns
.Columns("A:A").ColumnWidth = 40
.Columns("B:B").ColumnWidth = 22
.Columns("C:C").ColumnWidth = 73.44
End With

oSheet.Range("A:A").NumberFormat = "dd-mmm-yy "




With oSheet.Range("A1:" & Chr(iNumCols + 64) & rs.RecordCount + 1)
For Each C In oSheet.Range("A1:" & Chr(iNumCols + 64) & rs.RecordCount + 1).Cells
   If C.Value = "First TO" Then
    With C
        .Font.Name = "Arial"
        .Font.Bold = True
        .Font.Size = 12
        .Interior.ColorIndex = 15
        .Borders(xlEdgeTop).LineStyle = xlContinuous
        .Borders(xlEdgeTop).Weight = xlThin
        .Borders(xlEdgeTop).ColorIndex = xlAutomatic
        .Borders(xlEdgeBottom).LineStyle = xlContinuous
        .Borders(xlEdgeBottom).Weight = xlThin
        .Borders(xlEdgeBottom).ColorIndex = xlAutomatic
        .Borders(xlEdgeRight).LineStyle = xlContinuous
        .Borders(xlEdgeRight).Weight = xlThin
        .Borders(xlEdgeRight).ColorIndex = xlAutomatic
        .Borders(xlEdgeLeft).LineStyle = xlContinuous
        .Borders(xlEdgeLeft).Weight = xlThin
        .Borders(xlEdgeLeft).ColorIndex = xlAutomatic
        .Borders(xlInsideVertical).LineStyle = xlContinuous
        .Borders(xlInsideVertical).Weight = xlThin
        .Borders(xlInsideVertical).ColorIndex = xlAutomatic
        .Borders(xlInsideHorizontal).LineStyle = xlContinuous
        .Borders(xlInsideHorizontal).Weight = xlThin
        .Borders(xlInsideHorizontal).ColorIndex = xlAutomatic



     End With
    End If
Next C


Thank you, in advance, for any help you can give me!!!!! (I am very new to coding!!)
AnswerRe: Formatting Excel from Access: How do I apply conditional formatting with a loop? Pin
Chris Quinn28-Sep-14 21:15
Chris Quinn28-Sep-14 21:15 
GeneralRe: Formatting Excel from Access: How do I apply conditional formatting with a loop? Pin
Member 1111259729-Sep-14 7:10
Member 1111259729-Sep-14 7:10 
Questionicacls vbscript - disabling inheritance and removing permissions a security group Pin
Chris Cooper26-Sep-14 3:17
Chris Cooper26-Sep-14 3:17 
AnswerRe: icacls vbscript - disabling inheritance and removing permissions a security group Pin
Eddy Vluggen26-Sep-14 6:03
professionalEddy Vluggen26-Sep-14 6:03 
QuestionPloting xy grapgh on VB Pin
Member 1051522523-Sep-14 20:31
professionalMember 1051522523-Sep-14 20:31 
QuestionMore than 1 barcode reader in one pc Pin
Member 380289623-Sep-14 19:19
Member 380289623-Sep-14 19:19 
AnswerRe: More than 1 barcode reader in one pc Pin
Bernhard Hiller23-Sep-14 22:01
Bernhard Hiller23-Sep-14 22:01 
AnswerRe: More than 1 barcode reader in one pc Pin
Tino Fourie24-Sep-14 6:40
Tino Fourie24-Sep-14 6:40 
AnswerRe: More than 1 barcode reader in one pc Pin
ZurdoDev24-Sep-14 10:07
professionalZurdoDev24-Sep-14 10:07 
QuestionTextBox Validation Pin
Benniiit23-Sep-14 7:09
Benniiit23-Sep-14 7:09 
AnswerRe: TextBox Validation Pin
JR21223-Sep-14 21:18
JR21223-Sep-14 21:18 
QuestionRemove double spaces in a textbox on keypress Pin
Benniiit20-Sep-14 3:10
Benniiit20-Sep-14 3:10 
AnswerRe: Remove double spaces in a textbox on keypress Pin
Bernhard Hiller21-Sep-14 21:43
Bernhard Hiller21-Sep-14 21:43 
AnswerRe: Remove double spaces in a textbox on keypress Pin
Mycroft Holmes21-Sep-14 22:28
professionalMycroft Holmes21-Sep-14 22:28 
QuestionMultiline text box manipulating Pin
Member 1109601819-Sep-14 17:58
Member 1109601819-Sep-14 17:58 
SuggestionRe: Multiline text box manipulating Pin
Richard MacCutchan19-Sep-14 21:22
mveRichard MacCutchan19-Sep-14 21:22 
GeneralRe: Multiline text box manipulating Pin
Member 1109601819-Sep-14 22:17
Member 1109601819-Sep-14 22:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.